<?php
namespace logic\set\News;
/**
 * 新闻闻管理
 */
class NewsManage extends \logic\Base{
    
    
    /**
     * 读取一个新闻闻
     */
    public function getInfo($param){
        return D('News','setNews')->find($param);
    }
    
    public function add($data){
        
        $check = [            
            'siteid'    => ['reg'=>'int'],
            'adduserid' => ['reg'=>'int'],            
            'groupid'   => ['reg'=>'int'],
            'tags'      => '',          
            'sort'      => ['reg'=>'int'],
            'pic'       => ['check'=>'must','msg'=> '请上传广告图片'],
            'name'      => ['check'=>'must','msg'=> '请填写新闻闻名称'],
            'author'    => '',
            'des'       => '',
            'detail'    => '',
            'seo'       => ''            
        ];                
        $save = pVerify($check,$data);
        dump($save);
        if( is_array($save['tags'])) $save['tags'] = ','.implode(',',$save['tags']).',';
        if( is_array($save['seo'])) $save['seo'] = json_encode($save['seo']);
        $save = pFilter()->replace('set_News',$save,['name','des','detail','seo']); 
        echo 11;
        dump($save);exit;
        $id =  D('News','setNews')->add($save);
        pFilter()->save('set_News',$id);
        return $id;
        
    }
    
    /**
     * 修改
     */
    public function edit($id,$data){
        if( !$id )  logicE('修改ID不能为空');
        $check = [
            'adduserid' => ['reg'=>'int'],            
            'groupid'   => ['reg'=>'int'],
            'tags'      => '',          
            'sort'      => ['reg'=>'int'],
            'pic'       => '',// ['check'=>'must','msg'=> '请上传新闻图片'],
            'name'      => ['check'=>'must','msg'=> '请填写新闻闻名称'],
            'author'    => '',
            'des'       => '',
            'detail'    => '',
            'seo'       => ''            
        ];                
        $save = pVerify($check,$data);
        if( is_array($save['tags'])) $save['tags'] = ','.implode(',',$save['tags']).',';
        if( is_array($save['seo'])) $save['seo'] = json_encode($save['seo']);
        $save = pFilter()->replace('set_News',$save,['name','des','detail','seo']); 
        $id =  D('News','setNews')->edit($id,$save);
        pFilter()->save('set_News',$id);
        return $id;
        
    }
    
    /**
     * 更新状态
     */
    public function editStatus($id){
        $info = D('News','setNews')->find(['id'=>$id]);
        if( !$info ) return false;
        if( $this->CallUser->role == 'site' ){
            if( $this->getSiteId() != $info['siteid'] ) logicE('非法操作');
        }
        $data['status'] = $info['status']==1?2:1;
        return D('News','setNews')->edit($id,$data);
    }
    
    /**
     * 列表读取
     */
    public function getList($param){
        return D('NewsList','setNews')->getList($param);
    }
    
    
}